 var data = require('./JAreaData');
var fs    = require('fs');
var path  = require('path');
 var result = [];

 var pro  = data.prov;
 var city = data.city;
 var dist = data.dist;

 console.log(pro);
 
 for (let i = 0; i < pro.length; i++) {
     
 }

 for (const key in pro) {
     if (pro.hasOwnProperty(key)) {
        let temp  = {} ;
        temp.id = key;
        temp.name = pro[key];
        temp.children = [];
        for (const ckey in city) {
            if (city.hasOwnProperty(ckey)) {
               if(ckey===key){
                let areaArray = city[ckey];
                   temp.children = areaArray;
                   
                   for (let i = 0; i < areaArray.length; i++) {
                      let area = areaArray[i];
                      for (const akey in dist) {
                          if (dist.hasOwnProperty(akey)) {
                                if(area.id==akey) {
                                    area.children = dist[akey];
                                }
                          }
                      }
                   }
               }
            }
        }
        result.push(temp);
     }
 }

 var str = JSON.stringify(result);
 fs.writeFile(path.resolve(__dirname, "area.json"), str, function (err,                     
    data) {
   if (err) {
     console.error(err);
   }
   console.log('----------新增成功-------------');

    })